
package com.qin.springcloud.controller;

import com.qin.springcloud.bean.Users;
import com.qin.springcloud.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@RestController
public class UsersController {

    @Autowired
    private UsersService usersService;

    @Autowired
    private DiscoveryClient client;
    
    @GetMapping("/users/add")
    public void addUsers(Users users){
          usersService.addUsers(users);
    }
    
    @GetMapping("/users/getone")
    public int getOned(){
         return usersService.getOned();
    }

    @GetMapping("/users/get/{id}")
    public Users getById(@PathVariable int id){
       return usersService.getById(id);
    }

    @GetMapping("/users/getAll")
    public List<Users> getListAll(){
        return usersService.getlistAll();
    }
    
    @GetMapping("/users/getDiscovery")
    public Object discovery() {
    	List<String> services = this.client.getServices();
    	for (String string : services) {
			System.out.println(string);
		}
    	
    	List<ServiceInstance> instance = client.getInstances("springcloud-provider-users8001");
    	for (ServiceInstance serviceInstance : instance) {
    		System.out.println(serviceInstance.toString());
		}
    	return this.client;
    }

}

